home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevlj56.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  5.9 KB  |  214 lines

  1. /* Copyright (C) 1997, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevlj56.c,v 1.2 2000/09/19 19:00:13 lpd Exp $ */
  20. /* H-P LaserJet 5 & 6 drivers for Ghostscript */
  21. #include "gdevprn.h"
  22. #include "stream.h"
  23. #include "gdevpcl.h"
  24. #include "gdevpxat.h"
  25. #include "gdevpxen.h"
  26. #include "gdevpxop.h"
  27. #include "gdevpxut.h"
  28.  
  29. /* Define the default resolution. */
  30. #ifndef X_DPI
  31. #  define X_DPI 600
  32. #endif
  33. #ifndef Y_DPI
  34. #  define Y_DPI 600
  35. #endif
  36.  
  37. /* Define the number of blank lines that make it worthwhile to */
  38. /* start a new image. */
  39. #define MIN_SKIP_LINES 2
  40.  
  41. /* We round up the LINE_SIZE to a multiple of a ulong for faster scanning. */
  42. #define W sizeof(word)
  43.  
  44. private dev_proc_open_device(ljet5_open);
  45. private dev_proc_close_device(ljet5_close);
  46. private dev_proc_print_page(ljet5_print_page);
  47.  
  48. private const gx_device_procs ljet5_procs =
  49. prn_procs(ljet5_open, gdev_prn_output_page, ljet5_close);
  50.  
  51. gx_device_printer gs_lj5mono_device =
  52. prn_device(ljet5_procs, "lj5mono",
  53.        DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  54.        X_DPI, Y_DPI,
  55.        0, 0, 0, 0,
  56.        1, ljet5_print_page);
  57.  
  58. private const gx_device_procs lj5gray_procs =
  59. prn_color_procs(ljet5_open, gdev_prn_output_page, ljet5_close,
  60.         gx_default_gray_map_rgb_color,
  61.         gx_default_gray_map_color_rgb);
  62.  
  63. gx_device_printer gs_lj5gray_device = {
  64.     prn_device_body(gx_device_printer, lj5gray_procs, "lj5gray",
  65.             DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  66.             X_DPI, Y_DPI,
  67.             0, 0, 0, 0,
  68.             1, 8, 255, 0, 256, 1, ljet5_print_page)
  69. };
  70.  
  71. /* Open the printer, writing the stream header. */
  72. private int
  73. ljet5_open(gx_device * pdev)
  74. {
  75.     int code = gdev_prn_open(pdev);
  76.  
  77.     if (code < 0)
  78.     return code;
  79.     code = gdev_prn_open_printer(pdev, true);
  80.     if (code < 0)
  81.     return code;
  82.     {
  83.     gx_device_printer *const ppdev = (gx_device_printer *)pdev;
  84.     stream fs;
  85.     stream *const s = &fs;
  86.     byte buf[50];        /* arbitrary */
  87.  
  88.     swrite_file(s, ppdev->file, buf, sizeof(buf));
  89.     px_write_file_header(s, pdev);
  90.     sflush(s);        /* don't close */
  91.     }
  92.     return 0;
  93. }
  94.  
  95. /* Close the printer, writing the stream trailer. */
  96. private int
  97. ljet5_close(gx_device * pdev)
  98. {
  99.     gx_device_printer *const ppdev = (gx_device_printer *)pdev;
  100.     int code = gdev_prn_open_printer(pdev, true);
  101.  
  102.     if (code < 0)
  103.     return code;
  104.     px_write_file_trailer(ppdev->file);
  105.     return gdev_prn_close(pdev);
  106. }
  107.  
  108. /* Send the page to the printer.  For now, just send the whole image. */
  109. private int
  110. ljet5_print_page(gx_device_printer * pdev, FILE * prn_stream)
  111. {
  112.     gs_memory_t *mem = pdev->memory;
  113.     uint line_size = gdev_mem_bytes_per_scan_line((gx_device *) pdev);
  114.     uint line_size_words = (line_size + W - 1) / W;
  115.     uint out_size = line_size + (line_size / 127) + 1;
  116.     word *line = (word *)gs_alloc_byte_array(mem, line_size_words, W, "ljet5(line)");
  117.     byte *out = gs_alloc_bytes(mem, out_size, "ljet5(out)");
  118.     int code = 0;
  119.     int lnum;
  120.     stream fs;
  121.     stream *const s = &fs;
  122.     byte buf[200];        /* arbitrary */
  123.  
  124.     if (line == 0 || out == 0) {
  125.     code = gs_note_error(gs_error_VMerror);
  126.     goto done;
  127.     }
  128.     swrite_file(s, prn_stream, buf, sizeof(buf));
  129.  
  130.     /* Write the page header. */
  131.     {
  132.     static const byte page_header[] = {
  133.         pxtBeginPage,
  134.         DUSP(0, 0), DA(pxaPoint),
  135.         pxtSetCursor
  136.     };
  137.     static const byte mono_header[] = {
  138.         DUB(eGray), DA(pxaColorSpace),
  139.         DUB(e8Bit), DA(pxaPaletteDepth),
  140.         pxt_ubyte_array, pxt_ubyte, 2, 0xff, 0x00, DA(pxaPaletteData),
  141.         pxtSetColorSpace
  142.     };
  143.     static const byte gray_header[] = {
  144.         DUB(eGray), DA(pxaColorSpace),
  145.         pxtSetColorSpace
  146.     };
  147.  
  148.     px_write_page_header(s, (gx_device *)pdev);
  149.     px_write_select_media(s, (gx_device *)pdev, NULL);
  150.     PX_PUT_LIT(s, page_header);
  151.     if (pdev->color_info.depth == 1)
  152.         PX_PUT_LIT(s, mono_header);
  153.     else
  154.         PX_PUT_LIT(s, gray_header);
  155.     }
  156.  
  157.     /* Write the image header. */
  158.     {
  159.     static const byte mono_image_header[] = {
  160.         DA(pxaDestinationSize),
  161.         DUB(eIndexedPixel), DA(pxaColorMapping),
  162.         DUB(e1Bit), DA(pxaColorDepth),
  163.         pxtBeginImage
  164.     };
  165.     static const byte gray_image_header[] = {
  166.         DA(pxaDestinationSize),
  167.         DUB(eDirectPixel), DA(pxaColorMapping),
  168.         DUB(e8Bit), DA(pxaColorDepth),
  169.         pxtBeginImage
  170.     };
  171.  
  172.     px_put_us(s, pdev->width);
  173.     px_put_a(s, pxaSourceWidth);
  174.     px_put_us(s, pdev->height);
  175.     px_put_a(s, pxaSourceHeight);
  176.     px_put_usp(s, pdev->width, pdev->height);
  177.     if (pdev->color_info.depth == 1)
  178.         PX_PUT_LIT(s, mono_image_header);
  179.     else
  180.         PX_PUT_LIT(s, gray_image_header);
  181.     }
  182.  
  183.     /* Write the image data, compressing each line. */
  184.     for (lnum = 0; lnum < pdev->height; ++lnum) {
  185.     int ncompr;
  186.     static const byte line_header[] = {
  187.         DA(pxaStartLine),
  188.         DUS(1), DA(pxaBlockHeight),
  189.         DUB(eRLECompression), DA(pxaCompressMode),
  190.         pxtReadImage
  191.     };
  192.  
  193.     code = gdev_prn_copy_scan_lines(pdev, lnum, (byte *) line, line_size);
  194.     if (code < 0)
  195.         goto fin;
  196.     px_put_us(s, lnum);
  197.     PX_PUT_LIT(s, line_header);
  198.     ncompr = gdev_pcl_mode2compress_padded(line, line + line_size_words,
  199.                            out, true);
  200.     px_put_data_length(s, ncompr);
  201.     px_put_bytes(s, out, ncompr);
  202.     }
  203.  
  204.     /* Finish up. */
  205.   fin:
  206.     spputc(s, pxtEndImage);
  207.     spputc(s, pxtEndPage);
  208.     sflush(s);
  209.   done:
  210.     gs_free_object(mem, out, "ljet5(out)");
  211.     gs_free_object(mem, line, "ljet5(line)");
  212.     return code;
  213. }
  214.